<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<!--原料基础信息模态框-->
<div class="modal fade" id="modal-chooseMaterial" tabindex="-1" data-keyboard="true">
    <div class="modal-dialog" style="width: 1350px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">原料基础信息</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                                <form id="queryForm">
                                    <div class="row">
                                        <div class="form-inline">
                                            <div class="form-group" >
                                                <label>类型</label>
                                                <input type="text" name="matTypeName"
                                                       class="form-control"
                                                       placeholder="请输入原料类型">
                                            </div>
                                            <div class="form-group">
                                                <label>材质</label>
                                                <input type="text" name="matQualityName"
                                                       class="form-control"
                                                       placeholder="请输入原料材质">
                                            </div>
                                            <div class="form-group">
                                                <label>规格</label>
                                                <input type="text" name="matSpecName"
                                                       class="form-control"
                                                       placeholder="请输入原料规格">
                                            </div>
                                            <div class="form-group">
                                                <label>宽度</label>
                                                <input type="number" step="0.1" name="matWidth" class="form-control"
                                                       placeholder="请输入原料宽度">
                                            </div>
                                            <div class="form-group">
                                                <label>长度</label>
                                                <input type="number" step="0.1" name="matLength" class="form-control"
                                                       placeholder="请输入原料长度">
                                            </div>
                                            <div class="form-group">
                                                <label>米重/厚度</label>
                                                <input type="number" step="0.1" name="matHeight" class="form-control"
                                                       placeholder="请输入原料米重/厚度">
                                            </div>
                                            <div class="form-group">
                                                <label>原料分类</label>
                                                <select name="materialKind"
                                                        class="form-control">
                                                    <option value="板材">板材</option>
                                                    <option value="型材">型材</option>
                                                    <option value="" selected="selected">全部</option>
                                                </select>
                                            </div>
                                            <button type="button" class="btn btn-success" id="btn_materialSearch">搜索</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="box-body">
                                <table id="bootstrap-table" class="table table-bordered" width="100%">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<!--库存明细信息模态框-->
<div class="modal fade" id="modal-chooseStock">

    <div class="modal-dialog" style="width: 1350px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">原料库在库明细信息</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header" style="padding-bottom: 0px;">
                                <form id="queryStockForm">
                                    <div class="row">
                                        <div class="form-inline">
                                            <div class="form-group">
                                                <label>项目编号</label>
                                                <input type="text" id="ityProCode"
                                                       class="form-control"
                                                       placeholder="请输入项目编号/名称">
                                            </div>
                                            <div class="form-group">
                                                <label>跟踪号</label>
                                                <input type="text" id="ityTrackCode"
                                                       class="form-control"
                                                       placeholder="请输入跟踪号">
                                            </div>
                                            <div class="form-group">
                                                <label>
                                                    原料分类
                                                </label>
                                                <select id="materialKind"
                                                        class="form-control">
                                                    <option value="型材">型材</option>
                                                    <option value="板材">板材</option>
                                                    <option value="" selected="selected">全部</option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <label>原料类型</label>
                                                <select id="matTypeIdList" class="form-control selectpicker"
                                                        data-live-search="true" multiple>
                                                    <option th:each="type:${matType}" th:value="${type.mdId}"
                                                            th:text="${type.mdName}"></option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <label>原料材质</label>
                                                <select id="matQualityIdList"
                                                        class="form-control selectpicker"
                                                        data-live-search="true" multiple>
                                                    <option th:each="type:${matQuality}" th:value="${type.mdId}"
                                                            th:text="${type.mdName}"></option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <label>原料规格</label>
                                                <select id="matSpecIdList"
                                                        class="form-control selectpicker"
                                                        data-live-search="true" multiple>
                                                    <option th:each="type:${matSpec}" th:value="${type.mdId}"
                                                            th:text="${type.mdName}"></option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <label>宽度</label>
                                                <input type="number" step="0.1" id="matWidth" class="form-control"
                                                       placeholder="请输入原料宽度">
                                            </div>
                                            <div class="form-group">
                                                <label>长度</label>
                                                <input type="number" step="0.1" id="matLength" class="form-control"
                                                       placeholder="请输入原料长度">
                                            </div>
                                            <div class="form-group">
                                                <label>米重/厚度</label>
                                                <input type="number" step="0.1" id="matHeight" class="form-control"
                                                       placeholder="请输入原料米重/厚度">
                                            </div>
                                            <div class="form-group">
                                                <label>
                                                    在库类型
                                                </label>
                                                <select id="ityInType" class="form-control">
                                                    <option value="1">库存在库</option>
                                                    <option value="2" selected="selected">项目在库</option>
                                                    <option value="">全部</option>
                                                </select>
                                            </div>
                                            <button type="button" class="btn btn-success" id="btn_stockSearch">搜索</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="box-body">
                                <table id="bootstrap-stock-table">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
                <button type="button" class="btn btn-info" id="btn-selectMaterial-commit">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>

</div>

<section class="content-header">
    <h1>
        修改串料申请
    </h1>
</section>
<section class="content">
    <form id="changeOrderForm" method="post" class="form-horizontal" role="form"
          enctype="multipart/form-data">
        <input type="hidden" id="ceoId" name="ceoId" th:value="${changeOrder.ceoId}">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <div class="col-md-4 col-md-offset-5">
                            <h3>串料申请基本信息</h3>
                        </div>
                        <div class="col-md-3">单据编号：
                            <label id="ceoCode" name="ceoCode" th:text="${changeOrder.ceoCode}"></label>
                        </div>
                    </div>
                    <div class="box-body">
                        <div class="row">
                            <div class="col-md-10 col-md-offset-1">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="ceoNeedCode" class="col-sm-3 control-label">需求项目编号</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" id="ceoNeedCode"
                                                       th:value="${changeOrder.ceoNeedCode}"
                                                       name="ceoNeedCode" autocomplete="off" maxlength="8"
                                                       placeholder="需求项目编号">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="ceoLendCode" class="col-sm-3 control-label">挪用项目编号</label>
                                            <div class="col-sm-7" style="padding-right: 0px">
                                                <input type="hidden" name="ceoLendItyId"
                                                       id="ceoLendItyId"
                                                       th:value="${changeOrder.ceoLendItyId}">
                                                <input type="hidden" id="materialSpec"
                                                       th:value="${materialDictionary.mdName}">
                                                <input type="hidden" id="materialLength"
                                                       th:value="${material.matLength}">
                                                <input type="hidden" id="materialWidth"
                                                       th:value="${material.matWidth}">
                                                <input type="hidden" id="materialHeight"
                                                       th:value="${material.matHeight}">
                                                <input type="hidden" id="materialFormulaType"
                                                       th:value="${material.matFormulaType}">
                                                <input type="text" readonly="readonly" class="form-control"
                                                       id="ceoLendCode" th:value="${changeOrder.ceoLendCode}"
                                                       name="ceoLendCode" autocomplete="off" placeholder="挪用项目编号">
                                            </div>
                                            <div class="col-sm-2">
                                                <button type="button" class="btn btn-info pull-right"
                                                        id="btn-chooseStock">选择
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="ceoNeedName" class="col-sm-3 control-label">需求项目名称</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" id="ceoNeedName"
                                                       th:value="${changeOrder.ceoNeedName}"
                                                       name="ceoNeedName" autocomplete="off" placeholder="需求项目名称">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="ceoLendName" class="col-sm-3 control-label">挪用项目名称</label>
                                            <div class="col-sm-9">
                                                <input type="text" readonly="readonly" class="form-control"
                                                       th:value="${changeOrder.ceoLendName}"
                                                       id="ceoLendName" name="ceoLendName" autocomplete="off"
                                                       placeholder="挪用项目名称">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">计划归还编码</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" id="ceoNeedTrackCode"
                                                       th:value="${changeOrder.ceoNeedTrackCode}"
                                                       name="ceoNeedTrackCode" autocomplete="off" placeholder="计划归还编码">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">挪用计划编码</label>
                                            <div class="col-sm-9">
                                                <input type="text" readonly="readonly" id="ceoLendTrackCode"
                                                       th:value="${changeOrder.ceoLendTrackCode}"
                                                       name="ceoLendTrackCode" class="form-control" autocomplete="off"
                                                       placeholder="挪用计划编码">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="ceoNeedMatDesc" class="col-sm-3 control-label">名称材质规格</label>
                                            <div class="col-sm-7" style="padding-right: 0px">
                                                <input type="hidden" name="ceoNeedMatId" id="ceoNeedMatId"
                                                       th:value="${changeOrder.ceoNeedMatId}">
                                                <input type="text" readonly="readonly" class="form-control"
                                                       id="ceoNeedMatDesc" name="ceoNeedMatDesc" autocomplete="off"
                                                       placeholder="名称材质规格" th:value="${changeOrder.ceoNeedMatDesc}">
                                            </div>
                                            <div class="col-sm-2">
                                                <button type="button" id="btn-chooseMaterial"
                                                        class="btn btn-info pull-right">选择
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="ceoLendMatDesc" class="col-sm-3 control-label">名称材质规格</label>
                                            <div class="col-sm-9">
                                                <input type="text" readonly="readonly" class="form-control"
                                                       id="ceoLendMatDesc" name="ceoLendMatDesc" autocomplete="off"
                                                       placeholder="名称材质规格" th:value="${changeOrder.ceoLendMatDesc}">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">需求数量</label>
                                            <div class="col-sm-3">
                                                <input type="number" step="0.1" style="padding-right: 5px;"
                                                       class="form-control" id="ceoNeedQty" name="ceoNeedQty"
                                                       autocomplete="off" placeholder="数量"
                                                       th:value="${changeOrder.ceoNeedQty}">
                                            </div>
                                            <label class="col-sm-3 control-label">需求重量</label>
                                            <div class="col-sm-3">
                                                <input type="number" step="0.1" style="padding-right: 5px;"
                                                       class="form-control" id="ceoNeedWgt" name="ceoNeedWgt"
                                                       autocomplete="off" placeholder="重量"
                                                       th:value="${changeOrder.ceoNeedWgt}">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">剩余数量</label>
                                            <div class="col-sm-3">
                                                <input type="text" readonly="readonly" class="form-control"
                                                       id="ceoEndQty"
                                                       name="ceoEndQty" autocomplete="off" placeholder="剩余数量"
                                                       th:value="${changeOrder.ceoEndQty}">
                                            </div>
                                            <label class="col-sm-3 control-label">剩余重量</label>
                                            <div class="col-sm-3">
                                                <input type="text" readonly="readonly" class="form-control"
                                                       id="ceoEndWgt"
                                                       name="ceoEndWgt" autocomplete="off" placeholder="剩余重量"
                                                       th:value="${changeOrder.ceoEndWgt}">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">使用部门</label>
                                            <div class="col-sm-9">
                                                <select id="ceoNeedDept" class="form-control select2"
                                                        name="ceoNeedDept"
                                                        style="width: 100%;">
                                                    <option value="">请选择</option>
                                                    <option th:each="type:${dept}" th:value="${type.depName}"
                                                            th:text="${type.depName}"
                                                            th:selected="${changeOrder.ceoNeedDept eq type.depName }"></option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">所在部门</label>
                                            <div class="col-sm-9">
                                                <select id="ceoLendDept" class="form-control select2"
                                                        name="ceoLendDept"
                                                        style="width: 100%;">
                                                    <option value="">请选择</option>
                                                    <option th:each="type:${dept}" th:value="${type.depName}"
                                                            th:text="${type.depName}"
                                                            th:selected="${changeOrder.ceoLendDept eq type.depName }"></option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <hr>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">是否需要还料</label>
                                            <div class="col-sm-1" style="width: 30px;padding-top: 6px;">
                                                <input type="radio" name="ceoReturnFlg" value="1"
                                                       th:checked="${changeOrder.ceoReturnFlg == 1}">
                                            </div>
                                            <label class="col-sm-2 control-label pull-left"
                                                   style="width: 55px;padding-left: 0px;">需要</label>
                                            <div class="col-sm-1"
                                                 style="width: 30px;padding-top: 6px;padding-left: 50px;">
                                                <input type="radio" name="ceoReturnFlg" value="2"
                                                       th:checked="${changeOrder.ceoReturnFlg == 2}">
                                            </div>
                                            <label class="col-sm-2 control-label pull-left"
                                                   style="width: 65px;padding-left: 0px;">不需要</label>
                                        </div>
                                    </div>
                                </div>
                                <hr>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">需求项目生产状况</label>
                                    <div class="col-sm-11">
                                        <textarea rows="3" class="form-control" id="ceoNeedDesc" name="ceoNeedDesc"
                                                  autocomplete="off" placeholder="需求项目生产状况"
                                                  th:text="${changeOrder.ceoNeedDesc}"></textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">挪用项目生产状况</label>
                                    <div class="col-sm-11">
                                        <textarea rows="3" class="form-control" id="ceoLendDesc" name="ceoLendDesc"
                                                  autocomplete="off" placeholder="被挪用项目生产状况"
                                                  th:text="${changeOrder.ceoLendDesc}"></textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">备注</label>
                                    <div class="col-sm-11">
                                        <textarea rows="2" class="form-control" id="ceoRemark" name="ceoRemark"
                                                  autocomplete="off" placeholder="备注"
                                                  th:text="${changeOrder.ceoRemark}"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="row">
                            <div class="col-md-2 col-md-offset-1">
                                <label>制单人：</label><label th:text="${changeOrder.ceoBillUser}"></label>
                            </div>
                            <div class="col-md-7">
                                <label>制单时间：</label>
                                <label th:text="${#dates.format(changeOrder.ceoBillDate, 'yyyy-MM-dd hh:mm:ss')}"></label>
                            </div>
                            <div class="col-md-2">
                                <button type="button" id="btn_create" class="btn btn-info pull-left">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
<div th:include="include :: footer"></div>
<script>

    /**模态框加载表格变量*/
    var table1, table2;

    /**获取物料信息（模态框数据源）*/
    function openMaterialList() {
        table1 = js.table.init({
            url: ctx + "basic/materials/list",
            pageSize: 100,
            showExport: false,
            columns: [
                {
                    title: '序号', field: '', width: '40',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: '编码', field: 'matCode'},
                {title: '分类', field: 'materialKind'},
                {title: '类型', field: 'matTypeName'},
                {title: '材质', field: 'matQualityName'},
                {title: '规格', field: 'matSpecName'},
                {title: '宽度', field: 'matWidth'},
                {title: '长度', field: 'matLength'},
                {title: '米重/厚度', field: 'matHeight'},
                {
                    title: '选择', width: '60',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push("<a class='btn btn-info btn-xs' href='javascript:void(0);' onclick='getMaterial(" + JSON.stringify(row) + " )'>选择</a>");
                        return actions.join('');
                    }
                }
            ]
        });
    }

    /**获取物料在库信息（模态框数据源）*/
    function openInventoryList() {
        table2 = js.table.init({
            id: "bootstrap-stock-table",
            url: ctx + "matInvManage/complex/list",
            pageSize: 100,
            showExport: false,
            queryForm: "queryStockForm",
            queryData: {
                ityProCode: $("#ityProCode").val(),
                ityTrackCode: $("#ityTrackCode").val(),
                matTypeIdList: $("#matTypeIdList").val(),
                matQualityIdList: $("#matQualityIdList").val(),
                matSpecIdList: $("#matSpecIdList").val(),
                matWidth: $("#matWidth").val(),
                matLength: $("#matLength").val(),
                matHeight: $("#matHeight").val(),
                materialKind: $("#materialKind").val(),
                ityInType: $("#ityInType").val()
            },
            columns: [
                {
                    title: '序号', field: 'id', width: '40',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: '原料描述', field: 'matNameDesc'},
                {title: '在库数量', field: 'ityNum'},
                {title: '可用数量', field: 'ityAvaNum'},
                {title: '在库重量', field: 'ityWeight'},
                {title: '可用重量', field: 'ityAvaWeight'},
                {title: '跟踪号', field: 'ityTrackCode'},
                {title: '项目编码', field: 'ityProCode'},
                {title: '项目名称', field: 'ityProName'},
                {
                    title: '在库类型', field: 'ityInType',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '库存在库';
                        } else if (value === 2) {
                            return '项目在库';
                        }
                    }
                },
                {title: '特殊说明', field: 'itySpec'},
                {
                    title: '选择', width: '60',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push("<a class='btn btn-info btn-xs' href='javascript:void(0);' onclick='getStock(" + JSON.stringify(row) + " )'>选择</a>");
                        return actions.join('');
                    }
                }
            ],
            rowStyle: function (row, index) {
                if (row.itySpec != null && row.itySpec.indexOf("不合格") >= 0) {
                    return {css: {"color": "red"}}
                } else {
                    return {css: {"color": "black"}}
                }
            }
        });
    }

    /**取得原料行数据*/
    function getMaterial(d) {

        $("#ceoNeedMatId").val(d.matId);
        $("#ceoNeedWgtUnit").text(d.matWeightUnit);

        $("#materialSpec").val(d.matSpecName);
        $("#materialLength").val(d.matLength);
        $("#materialWidth").val(d.matWidth);
        $("#materialHeight").val(d.matHeight);
        $("#materialFormulaType").val(d.matFormulaType);

        $("#ceoNeedMatDesc").val(d.matNameDesc);

        // 关闭模态框
        js.modal.hide("modal-chooseMaterial");
    }

    /**取得在库明细行数据*/
    function getStock(c) {

        $("#ceoLendItyId").val(c.ityId);
        $("#ceoLendCode").val(c.ityProCode);
        $("#ceoLendName").val(c.ityProName);
        $("#ceoLendTrackCode").val(c.ityTrackCode);
        $("#ceoEndQtyUnit").text(c.matNumUnit);
        $("#ceoEndWgtUnit").text(c.matWeightUnit);

        $("#ceoLendMatDesc").val(c.matNameDesc);

        $("#ceoEndQty").val(c.ityAvaNum);
        $("#ceoEndWgt").val(c.ityAvaWeight);

        // 如果需求物料未选择，默认与挪用物料信息相同
        $("#ceoNeedMatId").val(c.matId);
        $("#ceoNeedWgtUnit").text(c.matWeightUnit);

        $("#materialSpec").val(c.matSpecName);
        $("#materialLength").val(c.matLength);
        $("#materialWidth").val(c.matWidth);
        $("#materialHeight").val(c.matHeight);
        $("#materialFormulaType").val(c.matFormulaType);
        $("#ceoNeedMatDesc").val(c.matNameDesc);

        $("#ceoNeedQty").val("");
        $("#ceoNeedWgt").val("");

        // 关闭模态框
        js.modal.hide("modal-chooseStock");
    }

    $(function () {

        /**打开物料模态框*/
        $("#btn-chooseMaterial").on('click', function () {
            openMaterialList();
            js.modal.open("modal-chooseMaterial")
        });

        /** 表格搜索原料 */
        $("#btn_materialSearch").click(function () {
            js.table.search(table1);
        });

        /**关闭物料模态框*/
        js.modal.hideEvent("modal-chooseMaterial", function () {
            js.table.destroy(table1);
            js.reset("queryForm");
        });

        /**需求数量 联动需求重量*/
        $("#ceoNeedQty").change(function () {

            var spec = $("#materialSpec").val();
            var length = $("#materialLength").val();
            var width = $("#materialWidth").val();
            var height = $("#materialHeight").val();
            var needQty = $("#ceoNeedQty").val();
            var formulaType = $("#materialFormulaType").val();

            var totalWeight = returnMaterialWeight(spec, length, width, height, needQty, formulaType);
            $("#ceoNeedWgt").val(totalWeight);
        });

        /**打开库存在库模态框*/
        $("#btn-chooseStock").on('click', function () {
            openInventoryList();
            js.modal.open("modal-chooseStock")
        });

        /** 表格搜索库存 */
        $("#btn_stockSearch").click(function () {
            js.table.destroy(table2);
            openInventoryList();
        });

        /**关闭库存在库模态框*/
        js.modal.hideEvent("modal-chooseStock", function () {
            js.table.destroy(table2);
            js.reset("queryStockForm");
        });

        /**分类下拉选值改变事件*/
        $("#materialKind").change(function () {

            js.get({
                url: ctx + "basic/materials/materialDictionary",
                data: {kindName: $('#materialKind option:selected').val()},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        $("#matTypeIdList").empty().append('<option value="">请选择</option>');
                        $.each(result.data.materialTypeList, function (i, v) {
                            $("#matTypeIdList").append('<option value="' + v.mdId + '">' + v.mdName + '</option>');
                        });
                        //必不可少的刷新
                        $("#matTypeIdList").selectpicker('refresh');

                        $("#matQualityIdList").empty().append('<option value="">请选择</option>');
                        $.each(result.data.materialQualityList, function (i, v) {
                            $("#matQualityIdList").append('<option value="' + v.mdId + '">' + v.mdName + '</option>');
                        });
                        //必不可少的刷新
                        $("#matQualityIdList").selectpicker('refresh');

                        $("#matSpecIdList").empty().append('<option value="">请选择</option>');
                        $.each(result.data.materialSpecList, function (i, v) {
                            $("#matSpecIdList").append('<option value="' + v.mdId + '">' + v.mdName + '</option>');
                        });
                        //必不可少的刷新
                        $("#matSpecIdList").selectpicker('refresh');
                    }
                }
            });
        });

        /**修改串料申请单*/
        $("#btn_create").click(function () {

            var ceoNeedMatDesc = $("#ceoNeedMatDesc").val();
            if (ceoNeedMatDesc == null || ceoNeedMatDesc == "") {
                js.modal.warning("请选择需求物料信息！");
                $("#ceoNeedMatDesc").focus();
                return false;
            }

            var ceoNeedName = $("#ceoNeedName").val();
            if (ceoNeedName == null || ceoNeedName == "") {
                js.modal.warning("请输入挪用项目名称！");
                $("#ceoNeedName").focus();
                return false;
            }

            var ceoLendMatDesc = $("#ceoLendMatDesc").val();
            if (ceoLendMatDesc == null || ceoLendMatDesc == "") {
                js.modal.warning("请输入挪用物料信息！");
                $("#ceoLendMatDesc").focus();
                return false;
            }

            var ceoNeedWgt = $("#ceoNeedWgt").val();
            if (ceoNeedWgt == null || ceoNeedWgt == "") {
                js.modal.warning("请输入需求重量！");
                $("#ceoNeedWgt").focus();
                return false;
            }

            var ceoNeedQty = $("#ceoNeedQty").val();
            var ceoNeedWgt = $("#ceoNeedWgt").val();
            var ceoEndQty = $("#ceoEndQty").val();
            var ceoEndWgt = $("#ceoEndWgt").val();

            if (ceoNeedQty != null && ceoNeedQty != "" && ceoEndQty != null && ceoEndQty != "" && parseFloat(ceoNeedQty) > parseFloat(ceoEndQty)) {

                js.modal.warning("需求数量大于可用数量！");
                $("#needQty").focus();
                return false;
            }

            if (ceoNeedWgt != null && ceoNeedWgt != "" && ceoEndWgt != null && ceoEndWgt != "" && parseFloat(ceoNeedWgt) > parseFloat(ceoEndWgt)) {

                js.modal.warning("需求重量大于可用重量！");
                $("#needWgt").focus();
                return false;
            }

            js.validSubmit({
                formId: "changeOrderForm",
                url: ctx + "material/changeOrder/edit",
                data: new FormData($("#changeOrderForm")[0]),
                success: function (result) {
                    location.href = ctx + "material/changeOrder/page";
                }
            });

        })

        // 验证初始化
        js.validate.init("changeOrderForm", {
            fields: {
                ceoNeedCode: {
                    validators: {
                        threshold: 6, //有6字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，6字符以上才开始）
                        notEmpty: {
                            message: '请输入需求项目编号'
                        },
                        // 发送ajax请求到后台查询，返回 valid：true或者false
                        callback: {
                            message: "项目号不存在",
                            callback: function (value, validator) {
                                var flag = false;
                                $.ajax({
                                    url: ctx + 'material/changeOrder/codeExist', // 请求路径
                                    type: 'POST',
                                    async: false,	// 同步请求，必须是false
                                    data: {
                                        ceoNeedCode: $('#ceoNeedCode').val() // 请求参数
                                    },
                                    success: function (res) {
                                        flag = $.parseJSON(res).valid;
                                    }
                                });
                                return flag;
                            }
                        }
                    }
                },
                ceoNeedName: {validators: {notEmpty: {message: '请输入需求项目名称'}}},
                ceoNeedQty: {validators: {notEmpty: {message: '请输入数量'}}},
                ceoNeedWgt: {validators: {notEmpty: {message: '请输入重量'}}},
                ceoNeedDept: {validators: {notEmpty: {message: '请输入使用部门'}}},
                ceoLendDept: {validators: {notEmpty: {message: '请输入所在部门'}}},
                ceoNeedDesc: {validators: {notEmpty: {message: '请输入需求项目生产状况'}}},
                ceoLendDesc: {validators: {notEmpty: {message: '请输入被挪用项目生产状况'}}},
            }
        });

        /** 项目编号 焦点离开 自动取得 名称 */
        $("#ceoNeedCode").blur(function () {
            js.get({
                url: ctx + "material/changeOrder/findProject",
                data: {proCode: $("#ceoNeedCode").val()},
                success: function (result) {
                    if (result.data == null) {
                        $("#ceoNeedName").val("");
                        $("#ceoNeedDesc").val("");
                    } else {
                        $("#ceoNeedName").val(result.data.proName);
                        $("#ceoNeedDesc").val(result.data.proStatus);
                    }
                }
            });
        });

    })

</script>

</body>
</html>